package networking;

import java.net.*;
import java.io.*;

public class Reciever implements Runnable {
	
	private int port;
	
	public Reciever(int portNum) throws IOException{
		this.port = portNum;
		System.out.println(port);
	}

	

	@Override
	public void run() {
		 ServerSocket serverSocket = null;
	        try {
	            serverSocket = new ServerSocket(this.port);
	        } catch (IOException e) {
	            System.err.println("Could not listen on port: " + this.port);
	            System.exit(1);
	        }

	        Socket clientSocket = null;
	        try {
	            clientSocket = serverSocket.accept();
	        } catch (IOException e) {
	            System.err.println("Accept failed.");
	            System.exit(1);
	        }

	        PrintWriter out = null;
	        BufferedReader in = null;
			try {
				
				in = new BufferedReader(
						new InputStreamReader(
						clientSocket.getInputStream()));
			} catch (IOException e) {
				
				e.printStackTrace();
			}
	        String inputLine;
	        Protocol kkp = new Protocol();
	 
	        try {
				while ((inputLine = in.readLine()) != null) {				     
				     System.out.println(inputLine);
				}
				in.close();		
				clientSocket.close();			
				serverSocket.close();
			} catch (IOException e) {
				
				e.printStackTrace();
			}
	       
	}
	
}
